import PictureWall from '@/components/picturewall';
import { Button, Spin, UploadProps, Image } from 'antd';
import React from 'react';
import { importFrom1688 } from '@/services/product';
import useSpinning from '@/uses/useSpinning';

declare global {
  interface Window {
    electronAPI: any
  }
}

const fileList: UploadProps['fileList'] = [
  {
    uid: '-1',
    name: 'image.png',
    status: 'done',
    url: 'https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png',
  },
  {
    uid: '-2',
    name: 'image.png',
    status: 'done',
    url: 'https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png',
  },
  {
    uid: '-3',
    name: 'image.png',
    status: 'done',
    url: 'https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png',
  },
  {
    uid: '-4',
    name: 'image.png',
    status: 'done',
    url: 'https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png',
  },
  {
    uid: '-xxx',
    percent: 50,
    name: 'image.png',
    status: 'uploading',
    url: 'https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png',
  },
  {
    uid: '-5',
    name: 'image.png',
    status: 'error',
  },
]


const DocsPage = () => {
  const [spinning, setSpinning] = React.useState<boolean>(false);
  const { SpinDom, show } = useSpinning({title: '加载中...'});

  const testOpenFile = async () => {
    setSpinning(true);
    const response = await window.electronAPI.wdioRunner('https://detail.1688.com/offer/724484714241.html');
    await importFrom1688(response)
    setSpinning(false);
  }

  return (
    <div>
      <p>This is umi docs.</p>
      <Button onClick={testOpenFile}>测试桌面端</Button>
      <PictureWall value={fileList} onChange={() => {}} />
      <Image
        width={200}
        src="/api/v1/files/viewImage/efe7c5b5dd0f09354cddcc8ef74bb075ed6c5f50cedf5a101f4902a1200f013c.png"
      />
      <Spin spinning={spinning} fullscreen />

      <Button onClick={() => {show(3000)}}>测试加载</Button>
      <SpinDom/>
    </div>
  );
};

export default DocsPage;
